﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class BasicDepartmentMore : DLL.MyWebPage
{
	private int nDepartmentID = 0;

	protected void Page_Load(object sender, EventArgs e)
	{
		try
		{
			nDepartmentID = Convert.ToInt32(Request["DepartmentID"]);
		}
		catch
		{
			nDepartmentID = 0;
		}

		if (!IsPostBack)
		{
			Show();
		}
	}

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);

		Grv.RowDataBound += new GridViewRowEventHandler(Grv_RowDataBound);
		Grv.DataBound += new EventHandler(Grv_DataBound);
		LBtnFirst.Click += new EventHandler(LBtnFirst_Click);
		LBtnForward.Click += new EventHandler(LBtnForward_Click);
		LBtnNext.Click += new EventHandler(LBtnNext_Click);
		LBtnLast.Click += new EventHandler(LBtnLast_Click);
	}

	void Grv_DataBound(object sender, EventArgs e)
	{
		GridView gv = new GridView();

		gv = (GridView)sender;

		if (gv.PageIndex == 0)
		{
			LBtnFirst.Enabled = false;
			LBtnForward.Enabled = false;
		}
		else
		{
			LBtnFirst.Enabled = true;
			LBtnForward.Enabled = true;
		}
		if (gv.PageIndex == gv.PageCount - 1)
		{
			LBtnLast.Enabled = false;
			LBtnNext.Enabled = false;
		}
		else
		{
			LBtnLast.Enabled = true;
			LBtnNext.Enabled = true;
		}
	}

	/// <summary>
	/// 最后一页
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void LBtnLast_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageCount - 1;
		Show();
	}

	/// <summary>
	/// 下一页
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void LBtnNext_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageIndex + 1;
		Show();
	}

	/// <summary>
	/// 上一页
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void LBtnForward_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageIndex - 1;
		Show();
	}

	/// <summary>
	/// 第一页
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void LBtnFirst_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = 0;
		Show();
	}

	void Grv_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		int nUploadFileID;
		GridView gv = new GridView();
		DLL.UploadFile.Component clsUploadFileComp = new DLL.UploadFile.Component(Page);

		gv = (GridView)sender;
		if (e.Row.RowIndex >= 0)
		{
			for (int i = 1; i <= 1; i++)
			{
				//if ((i != 0)  (i != (e.Row.Cells.Count - 1)))


				//LinkButton lBtnRead2 = new LinkButton();

				//lBtnRead2.Text = e.Row.Cells[i].Text;
				//lBtnRead2.CommandArgument = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
				//lBtnRead2.CommandName = lBtnRead.CommandName;
				//lBtnRead2.CssClass = lBtnRead.CssClass;
				e.Row.Cells[i].Controls.Clear();
				HyperLink aLink = new HyperLink();

				nUploadFileID = Convert.ToInt32(gv.DataKeys[e.Row.RowIndex].Value);


				aLink.CssClass = "Read";
				aLink.Text = e.Row.Cells[i].Text;
				//aLink.NavigateUrl = "../ShowImageContent.aspx?FileID=" + ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
				aLink.NavigateUrl = "~/ShowFileDetail.aspx?FileContentID=" + clsUploadFileComp.GetOne(nUploadFileID).FileContentID.ToString();
				aLink.Target = "_blank";

				e.Row.Cells[i].Controls.Add(aLink);

			}
		}
	}

	private void Show()
	{
		DLL.UploadFile.Component clsUploadFileComp = new DLL.UploadFile.Component(Page);
		List<DLL.UploadFile.Entity> list = new List<DLL.UploadFile.Entity>();
		DLL.Department.Component clsDepartmentComp = new DLL.Department.Component(Page);
		string strDepartments = "";

		strDepartments = clsDepartmentComp.QueryChildDepartmentID(nDepartmentID);
		//list = clsUploadFileComp.QueryByWebColumnID(15);
		list = clsUploadFileComp.QueryByDepartmentIDs(strDepartments);
		Grv.DataSource = list;
		Grv.DataKeyNames = new string[] { "ID" };
		Grv.DataBind();
	}
}